package com.example.food_contract_system.controller;

import com.example.food_contract_system.service.AgencyService;
import com.example.food_contract_system.util.R;
import com.example.food_contract_system.vo.AddAgencyVo;
import com.example.food_contract_system.vo.BossUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author LiHaoyang
 * @date 2023/7/6  10:28
 **/
@RestController
@RequestMapping("/index")
public class AgencyController {

    @Autowired
    private AgencyService agencyService;


    /**
     * 判断当前省份是否有总经销商
     * @param flag
     * @return
     */
    @PostMapping("/check/{newV}")
    public R check(@PathVariable("newV") boolean flag,
                   @RequestBody String region){
        R result = agencyService.check(flag,region);
        return result;
    }

    /**
     * 添加 代理商
     * @return
     */
    @PostMapping("/addAgency")
    public R addAgency(@RequestBody AddAgencyVo addAgencyVo){
        R result = agencyService.addAgency(addAgencyVo);
        return result;
    }

    /**
     * 获取 每个总经销商 下的经销商列表
     * @param aId
     * @return
     */
    @GetMapping("/getAgencyByBossAgency/{aId}")
    public R getAgencyByBossAgency(@PathVariable("aId")String aId){
        R result = agencyService.getAgencyByBossAgency(aId);
        return result;
    }

    @GetMapping("/getAgencyById/{aId}")
    public R getAgencyById(@PathVariable("aId") String aId){
        R result = agencyService.getAgencyById(aId);
        return result;
    }

    @PostMapping("/updateAgencyPwd/{aId}")
    public R updateAgencyPwd(@PathVariable("aId") String aId,
                             @RequestBody BossUpdateVo bossUpdateVo){
        R result = agencyService.updateAgencyPwd(aId,bossUpdateVo);
        return result;
    }

}
